<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html" />
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<include file="./Application/Home/View/Tpl/header.html" />



<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        首页
        <small>终端检索</small>
    </h1>
</section>

<!-- Main content -->
<section class="content">

<div class="row">

    <div class="col-md-12">
        <button class="btn pull-right  btn-success btn-lg" action="" id="scanstatus" name="scanstatus">
            扫描状态读取中... ...
        </button>
    </div>



</div>
<BR>
<div class="row">


<div class="col-md-12">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
    <li class="active" ><a href="#phone" data-toggle="tab">终端列表
        <empty name="scanterminaldata">
            <small class="label pull-right bg-green">0台</small>
            <else />
            <small class="label pull-right bg-green scanwifidata">{:count($scanterminaldata)}台</small>
        </empty>

    </a></li>
</ul>
<div class="tab-content">
    <div class="tab-pane active" id="phone">

        <div class="post">
            <div class="col-xs-12">
                <div style="float:  left" class="col-md-4">
                    <div class="input-group input-group-sm">
                        <input type="text" class="form-control" id="filtertxt">
                    <span class="input-group-btn">
                      <button class="btn btn-info btn-flat"  id="search" type="button">搜索</button>
                    </span>
                    </div>
                </div>



                <div style="float:  right">
                    <button class="btn   btn-danger" id="clearsta">
                        <i class="fa  fa-trash-o"></i> 清空终端列表
                    </button>
                </div>
                <BR>
                <BR>
                <div class="box" id="stalist">

                    <empty name="scanterminaldata">
                        尚未扫描到任何手机终端。
                        <else />
                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <tbody><tr>
                                    <th>序号</th>
                                    <th>终端MAC地址</th>
                                    <th>目的地址</th>
                                    <th>网络地址</th>
                                    <th>请求链接SSID</th>
                                    <!-- <th>设备距离</th>-->
                                    <th>设备名称</th>
                                    <th>信号强度</th>
                                    <th>距离</th>
                                    <th>捕获时间</th>
                                </tr>
                                <foreach name="scanterminaldata" item="vo" key="k" >

                                    <tr>
                                        <td>{$k+1} </td>
                                        <td>
                                             {$vo['smac']}
                                        </td>
                                        <td>
                                            {$vo['dmac']}
                                        </td>
                                        <td>
                                            {$vo['imac']}
                                        </td>
                                        <td>
                                            <span style="font-size: 14px" class="label label-primary">{$vo['requsetssid']}</span>
                                        </td>
                                        <!--<td>{$vo['ssid']} </td> -->
                                        <td>{$vo['devName']} </td>
                                        <td>
                                            <span class="signalstrength" signalstrength="{$vo['signalstrength']}">

                                                获取中
                                            </span>
                                        </td>
                                        <td>

                                            <a class="btn getdistance" mac="{$vo['smac']}"  signalstrength="{-$vo['signalstrength']}">
                                                <i class="fa fa-repeat"></i> 距离[获取中]
                                            </a>
                                        </td>
                                        <td>
                                            {$vo['time']|substr=0,4}年{$vo['time']|substr=4,2}月
                                            {$vo['time']|substr=6,2}日
                                            {$vo['time']|substr=8,2}:{$vo['time']|substr=10,2}:{$vo['time']|substr=12,2}
                                        </td>
                                    </tr>
                                </foreach>



                                </tbody></table>
                        </div>
                    </empty>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.user-block -->
            <p> &nbsp;
            </p>
            <ul class="list-inline">
            </ul>

        </div>
    </div>
    <!-- /.post -->
<BR>
</div>
<!-- /.tab-pane -->


</div>
<!-- /.tab-content -->
</div>
</div>
</div>

</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->


<include file="./Application/Home/View/Tpl/footer.html" />


<div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<include file="./Application/Home/View/Tpl/commjs.html" />
<script src="__PUBLIC__/dist/plugins/sparkline/jquery.sparkline.min.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function(){
        $('#search').click(function(){
            var sstxt=$('#filtertxt').val();
            $("table tbody tr").hide().filter(":contains('MAC'),:contains('"+sstxt+"')").show();
        });

        $(".getdistance").each(function(){
            $(this).html('距离['+Math.round(Math.pow(10,Math.abs(parseInt($(this).attr('signalstrength')))
                /(10*4))*10)/100 +'米] <i class="fa fa-repeat"></i>&nbsp;');
        });

        var interval;
        $(".getdistance").click(function(){
            var mac = $(this).attr('mac');
            var dis=$(this);
            $(this).html('获取中...');
            $.ajax({
                url : "{:U('/Home/scanwifi/getStrength','',false)}",
                type : "post",
                dataType : "json",
                data: {mac:mac},
                timeout:30000,
                success:function(result){
                    console.log(result);
                    if(result.signalstrength){
                        var sl=parseInt(result.signalstrength);
                        dis.html('距离['+Math.round(Math.pow
                        (10,Math.abs( sl)
                            /(10*4))*10)/100 +'米] <i class="fa fa-repeat"></i>&nbsp;');
                    }
                    //启动每秒定时刷新功能
                    clearInterval(interval);
                    interval=window.setInterval(getcurrentdistence, 2000);
                    function getcurrentdistence( )
                    {
                        dis.html('获取中...');
                        $.ajax({
                            url : "{:U('/Home/scanwifi/getStrength','',false)}",
                            type : "post",
                            dataType : "json",
                            data: {mac:mac},
                            timeout:30000,
                            success:function(result){
                                console.log(result);
                                if(result.signalstrength){
                                    var sl=parseInt(result.signalstrength);
                                    dis.html('距离['+Math.round(Math.pow
                                    (10,Math.abs( sl)
                                        /(10*4))*10)/100 +'米] <i class="fa fa-repeat"></i>&nbsp;');
                                }
                            },
                            error:function(msg){
                                console.log(msg);      //执行错误
                            }
                        });
                    }
                },
                error:function(msg){
                    console.log(msg);      //执行错误
                }
            });
        });

        $(".signalstrength").each(function(){
            var signal= -parseInt($(this).attr('signalstrength'));
            var str="弱";
            if(signal>90){
                str="强";
            }else if(signal>75){
                str="中";
            }else if(signal>60){
                str="一般";
            }
            else{
                str="弱";
            }
            //$(this).html(signal+'['+str+']');
            $(this).html(signal);
        });
    });

    $('#stopscan').click(function () {
        $.ajax({
            url : "{:U('/Home/scanwifi/stopscan','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:3000,
            success:function(result){
                if(result.status=="start"){
                    $("#stop").hide();
                    $("#start").show( );
                }

            },
            error:function(msg){
                console.log(msg);      //执行错误
                alert("系统错误!");
            }

        });
    });

    $('#startscan').click(function () {
        $.ajax({
            url : "{:U('/Home/scanwifi/startscan','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:3000,
            success:function(result){
                console.log(result);
                if(result.status=="stop"){
                    $("#start").hide();
                    $("#stop").show( );

                }
            },
            error:function(msg){
                console.log(msg);      //执行错误
                alert("系统错误!");
            }

        });
    });

    $("#clearsta").click(function(){
        $.ajax({
            url : "{:U('/Home/scanwifi/DatabaseClearSTA','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:3000,
            success:function(result){
                console.log(result);
                $("#stalist").remove();
                $(".scanwifidata").html('');
            },
            error:function(msg){
                console.log(msg);      //执行错误
                alert("系统错误!");
            }
        });
    });

    $.ajax({
        url : "{:U('/Home/scanwifi/getscanstatus','',false)}",
        type : "post",
        dataType : "json",
        data: null,
        timeout:3000,
        success:function(result){
            if(result.scanstatus=="runing"){
                $("#scanstatus").attr('action','stop');
                $("#scanstatus").html('停止扫描');
                $("#scanstatus").attr('class','btn pull-right  btn-success btn-lg');
            }
            else{
                $("#scanstatus").attr('action','start');
                $("#scanstatus").html('开启扫描');
                $("#scanstatus").attr('class','btn pull-right  btn-primary btn-lg');
            }
        },
        error:function(msg){
            console.log(msg);      //执行错误
            $("#scanstatus").attr('action','start');
            $("#scanstatus").html('扫描组件状态未知');
        }

    });
    $('#scanstatus').click(function () {
        var action=$(this).attr('action');
        $.ajax({
            url : "{:U('/Home/scanwifi/doscan','',false)}",
            type : "post",
            dataType : "json",
            data: {action:action},
            timeout:3000,
            success:function(result){
                if(result.status=="stop"){
                    $("#scanstatus").attr('action','stop');
                    $("#scanstatus").html('停止扫描');
                    $("#scanstatus").attr('class','btn  pull-right btn-success btn-lg');
                }
                else{
                    $("#scanstatus").attr('action','start');
                    $("#scanstatus").html('开启扫描');
                    $("#scanstatus").attr('class','btn pull-right  btn-primary btn-lg');
                }

            },
            error:function(msg){
                console.log(msg);      //执行错误
                $("#scanstatus").attr('action','start');
                $("#scanstatus").html('扫描组件状态未知');
            }

        });
    });



</script>

</body>
</html>


